export default function (context) {
    let isMobile = (ua) => {
        return !!ua.match(/AppleWebKit.*Mobile.*/)
    }
    let userAgent = context.req ? context.req.headers['user-agent'] : (process.browser ? navigator.userAgent : '')
    let isM = context.route.fullPath.includes('/m')

    if (isMobile(userAgent)) {
        if (isM) {
            return context.route.fullPath
        } else {
            context.redirect('/m')
        }
    } else {
        if (isM) {
            return context.redirect('/')
        }
        return context.route.fullPath
    }
}
